//@charset "utf-8";
//选中的股票代码
define(function (require, exports, module) {
	var Backbone = require('backbone');
	var CodeListModel = Backbone.Model.extend({
		codelist:{},
		getCodeList : function () {
			return this.codelist;
		},
		//@return "60000,600001,600020"
		getCodeListStr : function () {
			var str = '';
			$.each(this.codelist,function(attr,value){
				str = str + attr + ',';
			});
			str = str.substring(0,str.length-1);
			return str;
		},
		//@return [60000,600001]
		getCodeListArr: function(){
			var arr = [];
			$.each(this.codelist,function(attr,value){
				arr.push(parseInt(attr));
			});
			return arr;
		},
		//@param [600000,600001,600002]
		addCodeList: function(codes){
			var self = this;

			$.each(codes,function(i,code){
				self.codelist[code.toString()] = 1;
			});
		},
		clearCodeList: function(){
			this.codelist = {};
		},
		//@param  [600000,600001,600002]
		setCodeList: function(codes){
			var self = this;

			this.codelist = {};
			$.each(codes,function(i,code){
				self.codelist[code.toString()] = 1;
			});
		},
		// @param  [600000,600001,600002]
		removeCodeList: function(codes){
			var self = this;
			for (var i in codes) {

				delete self.codelist[codes[i]];
			}
			
		},
		// 对当前页进行的股票代码进行覆盖
		coverCodeList: function(){
			var self = this;

			var $doms = $('.data-stock');
			$.each($doms,function(i,dom){
				var code = $(dom).attr('data-stock').toString();
				if($(dom).hasClass('data-stock-select')){
					self.codelist[code] = 1;
				}else {
					delete self.codelist[code];
				}
			});

			// alert(JSON.stringify(self.codelist));
		}
	});

	module.exports = new CodeListModel();
});
